package craky.keeper.category;

import java.io.Serializable;

public class Category implements Serializable, Comparable<Category> {
	private static final long serialVersionUID = 2085530002657221873L;
	public static final int TYPE_SYSTEM = 0;
	public static final int TYPE_CUSTOM = 1;
	public static final String SYSTEM_DES = "系统类别";
	public static final String CUSTOM_DES = "用户类别";
	private int id;
	private String name;
	private int type;
	private long count;

	public Category() {
	}

	public Category(String name) {
		this.name = name;
		this.type = 1;
		this.count = 0L;
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getType() {
		return this.type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public long getCount() {
		return this.count;
	}

	public void setCount(long count) {
		this.count = count;
	}

	public String getTypeName() {
		String tn = null;

		switch (this.type) {
		case 0:
			tn = "系统类别";
			break;
		case 1:
			tn = "用户类别";
		}

		return tn == null ? "" : tn;
	}

	public void setTypeName(String typeName) {
		setType(getTypeByName(typeName));
	}

	public static int getTypeByName(String typeName) {
		if (typeName.equals("系统类别")) {
			return 0;
		}

		return 1;
	}

	@Override
	public String toString() {
		return this.name;
	}

	public int compareTo(Category category) {
		return this.type == category.getType() ? this.id - category.getId()
				: category.getType() - this.type;
	}
}